import {
	getCode
} from '@/api/login.js'
// 封装成类
class Request {

	constructor(baseURL) {
		this.baseURL = baseURL
	}
	request(options) {
		const {
			url
		} = options



		return new Promise((resolve, reject) => {
			wx.request({
				...options,
				url: this.baseURL + url,
				success: (res) => {
					resolve(res.data)
				},
				fail: (err) => {
					console.log("err:", err);
				}
			})
		})
	}
	get(options) {
		return this.request({
			...options,
			method: "get"
		})
	}
	post(options) {
		return this.request({
			...options,
			method: "post"
		})
	}
}

export const loginRequest = new Request("http://127.0.0.1:8080/")
//export const loginRequest = new Request("https://prdservice.com/chat/wechat/client/")


export function getDate(date, AddDayCount = 0) {
	if (!date) {
		date = new Date()
	}
	if (typeof date !== 'object') {
		date = date.replace(/-/g, '/')
	}
	const dd = new Date(date)

	dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期

	const y = dd.getFullYear()
	const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期，不足10补0
	const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
	return {
		fullDate: y + '-' + m + '-' + d,
		year: y,
		month: m,
		date: d,
		day: dd.getDay()
	}
}